package com.hjc.springbootmovies.mapper;

import com.hjc.springbootmovies.entity.ModelBroad;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: HJC
 * Date: 2019/12/6
 * Time: 9:00
 * To change this template use File | Settings | File Templates.
 */
@Mapper
public interface MappingBorad {

    @Select("SELECT b.xid,b.fid,b.tid,b.eid,f.fname,t.tname,e.ename,b.begintime,b.endtime,b.xmoney " +
            "FROM broad b , fiml f , hall t, emp e " +
            "WHERE b.fid = f.fid and t.tid = b.tid and b.eid = e.eid")
    @Results({
            @Result( property = "xid" , column = "xid"),
            @Result( property = "fid" , column = "fid"),
            @Result( property = "tid" , column = "tid"),
            @Result( property = "eid" , column = "eid"),
            @Result( property = "begintime" , column = "begintime"),
            @Result( property = "endtime" , column = "endtime"),
            @Result( property = "xmoney" , column = "xmoney"),
            @Result( property = "modelFiml" , column = "fid" ,one = @One(select = "com.hjc.springbootmovies.mapper.MappingFiml.queryById" ,fetchType = FetchType.EAGER)),
            @Result( property = "modelHall" , column = "tid" ,one = @One(select = "com.hjc.springbootmovies.mapper.MappingHall.queryById" ,fetchType = FetchType.EAGER)),
            @Result( property = "modelEmp" , column = "eid",one = @One(select = "com.hjc.springbootmovies.mapper.MappingEmp.queryById" ,fetchType = FetchType.EAGER))
    })
    List<ModelBroad> queryBorad();

    @Select("SELECT b.xid,b.fid,b.tid,b.eid,f.fname,t.tname,e.ename,b.begintime,b.endtime,b.xmoney " +
            "FROM broad b , fiml f , hall t, emp e " +
            "WHERE b.fid = f.fid and t.tid = b.tid and b.eid = e.eid and xid=#{xid} ")
    @Results({
            @Result( property = "xid" , column = "xid"),
            @Result( property = "fid" , column = "fid"),
            @Result( property = "tid" , column = "tid"),
            @Result( property = "eid" , column = "eid"),
            @Result( property = "begintime" , column = "begintime"),
            @Result( property = "endtime" , column = "endtime"),
            @Result( property = "xmoney" , column = "xmoney"),
            @Result( property = "modelFiml" , column = "fid" ,one = @One(select = "com.hjc.springbootmovies.mapper.MappingFiml.queryById" ,fetchType = FetchType.EAGER)),
            @Result( property = "modelHall" , column = "tid" ,one = @One(select = "com.hjc.springbootmovies.mapper.MappingHall.queryById" ,fetchType = FetchType.EAGER)),
            @Result( property = "modelEmp" , column = "eid",one = @One(select = "com.hjc.springbootmovies.mapper.MappingEmp.queryById" ,fetchType = FetchType.EAGER))
    })
    ModelBroad queryById(int xid);

    @Delete("DELETE FROM broad WHERE xid = #{xid} ")
    int deleteById(int xid);

    @Insert("INSERT INTO broad(fid,tid,eid,begintime,endtime,xmoney) VALUES(#{fid},#{tid},#{eid},#{begintime} ,#{endtime} ,#{xmoney} )")
    @Options( useGeneratedKeys = true , keyColumn = "xid")
    int addBroad(ModelBroad modelBroad);

    @Update("UPDATE broad SET fid=#{fid} ,tid=#{tid},eid=#{eid} ,begintime=#{begintime} ,endtime=#{endtime} ,xmoney=#{xmoney} WHERE xid=#{xid} ")
    int updateBroad(ModelBroad modelBroad);
}
